/*
  Copyright © 2010  Vinícius dos Santos Oliveira

      This file is part of Touché.

      Touché is free software: you can redistribute it and/or modify
      it under the terms of the GNU Lesser General Public License as published
      by the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU Lesser General Public License for more details.

      You should have received a copy of the GNU Lesser General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

#ifndef SCRIBBLE_H
#define SCRIBBLE_H

#include "toucheelement.h"
#include "widgets/scribbleareaitem.h"
#include "widgets/pushbuttonitem.h"

#ifndef TOUCHE_SHOULD_SKIP_THIS

class ScribbleItem: public QGraphicsItem
{
    static const QImage nullImage;

    QImage m_image;

public:
    ScribbleItem(const QImage &image, QGraphicsItem *parentItem = 0);

    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    void setImage(const QImage &image);
};

#endif

namespace Touche {

    class ScribbleElement : public Element
    {
        Q_OBJECT

        static const QImage nullImage;

        bool locked;
        ScribbleAreaItem *scribbleArea;
        QImage image;
        QString fileName;
        PushButtonItem *menu[5];
        QPen pen;
        QPen eraserPen;

        QGraphicsItem *m_item;

    public:
        ScribbleElement();
        ~ScribbleElement();
        const QString &type() const;
        QRectF item(QGraphicsItem *parentItem) const;
        QVector<QString> menuOptions() const;
        QString file();
        void load(const QString &xml, const QString &file);
        QString save() const;

    public slots:
        void onMenuActived(const QString &option);
        void onSceneReceived(QGraphicsScene *scene);
        void onElementLocked(bool locked);

    private slots:
        void onFinish();
        void onPenButtonClicked();
        void onEraserButtonClicked();
        void onColorChoose();
        void onSizeChanged(unsigned);
    };

} // namespace Touche

#endif // SCRIBBLE_H
